package com.stone.design.mode.state;

/**
 * 环境(状态机)
 *
 * @author Mr_wenpan@163.com 2022/01/13 22:41
 */
public class Context {

    /**
     * 状态机中枚举所有的状态
     */
    public final static OpeningState OPENING_STATE = new OpeningState();
    public final static ClosingState CLOSING_STATE = new ClosingState();
    public final static RunningState RUNNING_STATE = new RunningState();
    public final static StoppingState STOPPING_STATE = new StoppingState();

    /**
     * 聚合一个抽象状态
     */
    private LiftState liftState;

    /**
     * 设置环境中的状态
     */
    public void setLiftState(LiftState liftState) {
        this.liftState = liftState;
        // 把当前的环境通知到各个实现类中
        this.liftState.setContext(this);
    }

    public LiftState getLiftState() {
        return liftState;
    }

    public void open() {
        liftState.open();
    }

    public void close() {
        liftState.close();
    }

    public void run() {
        liftState.run();
    }

    public void stop() {
        liftState.stop();
    }

}
